package buildcode.support.plugin;

import java.util.List;

import org.apache.commons.lang3.ArrayUtils;

import buildcode.build.IPlugin;
import buildcode.config.EntityExportConfig;
import buildcode.database.DataBaseTable;
import buildcode.language.Field;
import buildcode.language.Type;

public class IncludeFieldPlugin implements IPlugin {

    private String[] includeField = {};

    @Override
    public Type beforeExport(Type type, String contextId, List<DataBaseTable> bases, EntityExportConfig entityConfig) {
        if (includeField.length == 0) {
            return type;
        }
        type.setFields(type.getFields().stream().filter(v -> ArrayUtils.contains(includeField, ((Field) v).getFieldName())).toList());
        return type;
    }

    public IncludeFieldPlugin(String[] includeField) {
        super();
        this.includeField = includeField;
    }

}
